#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
int* intersection(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize) 
{
    int hash[1000] = { 0 };
    int count = 0;
    int* ret = (int*)malloc(sizeof(int) * 1000);
    int i = 0;
    for (i = 0; i < nums1Size; i++)
    {
        hash[nums1[i]] = 1;
    }
    for (i = 0; i < nums2Size; i++)
    {
        if (hash[nums2[i]] == 1)
        {
            ret[count] = nums2[i];
            count++;
            hash[nums2[i]] = 0;
        }
    }
    *returnSize = count;
    return ret;
}
int main()
{
    int len1 = 0;
    int len2 = 0;
    int retsize = 0;
    int i = 0;
    scanf("%d%d", &len1,&len2);
    int* arr1 = (int*)malloc(sizeof(int) * len1);
    int* arr2 = (int*)malloc(sizeof(int) * len2);
    for (i = 0; i < len1; i++)
    {
        scanf("%d", &arr1[i]);
    }
    for (i = 0; i < len2; i++)
    {
        scanf("%d", &arr2[i]);
    }
    int* ret = intersection(arr1, len1,arr2,len2, &retsize);
    for (i = 0; i < retsize; i++)
    {
        printf("%d ", *(ret + i));
    }
    return 0;
}